﻿/**
 * 
 */
package views;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.util.Date;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JButton;
import javax.swing.JTextField;
import javax.swing.JTextArea;
import com.toedter.calendar.JDateChooser;

import controllers.ApplyButtonListener;

import javax.swing.JSpinner;
import javax.swing.SpinnerDateModel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;

/**
 * @author LAP
 *
 */
public class AddNewEventFrame extends JFrame {
	private JTextField eventName;
	private JTextArea eventDescription;
	private JButton addButton;
	private JDateChooser eventEndDate;
	private JSpinner eventEndTime;
	private JPanel buttonsPanel;
	private JPanel content;
	/**
	 * 
	 */
	private static final long serialVersionUID = -6499060942577000319L;
	
	public AddNewEventFrame(String title){
		super(title);
		createGUI();
	}
	
	/**
	 * @return the eventName
	 */
	public JTextField getEventName() {
		return eventName;
	}

	/**
	 * @param eventName the eventName to set
	 */
	public void setEventName(String eventName) {
		this.eventName.setText(eventName);
	}

	/**
	 * @return the eventDescription
	 */
	public JTextArea getEventDescription() {
		return eventDescription;
	}

	/**
	 * @param eventDescription the eventDescription to set
	 */
	public void setEventDescription(String eventDescription) {
		this.eventDescription.setText(eventDescription);
	}

	/**
	 * @return the eventEndDate
	 */
	public JDateChooser getEventEndDate() {
		return eventEndDate;
	}

	/**
	 * @param eventEndDate the eventEndDate to set
	 */
	public void setEventEndDate(Date eventEndDate) {
		this.eventEndDate.setDate(eventEndDate);
	}

	/**
	 * @return the eventEndTime
	 */
	public JSpinner getEventEndTime() {
		return eventEndTime;
	}

	/**
	 * @param eventEndTime the eventEndTime to set
	 */
	public void setEventEndTime(JSpinner eventEndTime) {
		
	}

	private void createGUI(){
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		content = new JPanel(new GridBagLayout());
		add(content, BorderLayout.CENTER);
		createFirstLine();
		createSecondLine();
		createThirdLine();
		createFourthLine();
		setMinimumSize(new Dimension(400, 250));
		pack();
		setVisible(true);
	}
	
	private void createFirstLine(){
		content.add(new JLabel("Название:"),
				new GridBagConstraints(0, 0, 1, 1, 0, 0, 
						GridBagConstraints.LINE_START, 
						GridBagConstraints.HORIZONTAL, 
						new Insets(2, 2, 0, 0), 0, 0));
		eventName = new JTextField();
		content.add(eventName,
				new GridBagConstraints(1, 0, 2, 1, 1, 0, 
						GridBagConstraints.LINE_START, 
						GridBagConstraints.HORIZONTAL, 
						new Insets(2, 2, 0, 2), 0, 0));
	}
	
	private void createSecondLine(){
		content.add(new JLabel("Дата/Время:"),
				new GridBagConstraints(0, 1, 1, 1, 0, 0, 
						GridBagConstraints.LINE_START, 
						GridBagConstraints.HORIZONTAL, 
						new Insets(2, 2, 0, 0), 0, 0));
		eventEndDate = new JDateChooser(new Date());
		content.add(eventEndDate,
				new GridBagConstraints(1, 1, 1, 1, 1, 0, 
						GridBagConstraints.LINE_START, 
						GridBagConstraints.HORIZONTAL, 
						new Insets(2, 2, 0, 0), 0, 0));
		eventEndTime = new JSpinner(new SpinnerDateModel());
		eventEndTime.setEditor(new JSpinner.DateEditor(eventEndTime, "HH:mm:ss"));
		content.add(eventEndTime,
				new GridBagConstraints(2, 1, 1, 1, 1, 0, 
						GridBagConstraints.LINE_START, 
						GridBagConstraints.HORIZONTAL, 
						new Insets(2, 2, 0, 2), 0, 0));
	}
	
	private void createThirdLine(){
		content.add(new JLabel("Описание:"),
				new GridBagConstraints(0, 2, 3, 1, 1, 0, 
						GridBagConstraints.CENTER, 
						GridBagConstraints.CENTER, 
						new Insets(2, 2, 0, 2), 0, 0));
		eventDescription = new JTextArea();
		eventDescription.setLineWrap(true);
		eventDescription.setWrapStyleWord(true);
		content.add(new JScrollPane(eventDescription), 
				new GridBagConstraints(0, 3, 3, 1, 1, 1, 
						GridBagConstraints.CENTER, 
						GridBagConstraints.BOTH, 
						new Insets(2, 2, 0, 0), 0, 0));
	}
	
	private void createFourthLine(){
		buttonsPanel = new JPanel(new GridBagLayout());
		addButton = new JButton("Добавить");
		buttonsPanel.add(addButton,
				new GridBagConstraints(0, 0, 1, 1, 1, 0, 
						GridBagConstraints.LINE_END, 
						GridBagConstraints.NONE, 
						new Insets(2, 0, 2, 2), 0, 0));
		addButton.addMouseListener(new ApplyButtonListener());
		add(buttonsPanel,BorderLayout.PAGE_END);
	}
}
